"""
  模块描述：接收超级短信模块报告的服务端-示例
  @author 8522
  @date 2022-05-18 10:04:01
  版权所有 Copyright www.dahantc.com
"""

import json

from flask import Flask, request
import supermsgReceiveEntity

app = Flask(__name__)


# 审核状态报告接收服务
@app.route('/receiveExamineReport', methods=['POST'])
def receiveExamineReport():
    res = supermsgReceiveEntity.ExamineReportReceiveResponse("success")
    try:
        report = request.form.get('supsmstempreport')
        smsDeliverResponse = supermsgReceiveEntity.ExamineReportReceiveParam.parseObj(json.loads(report))
        print('收到超级短信审核状态报告：', str(smsDeliverResponse.parseDict()))
    except Exception as e:
        print('数据解析异常 %s' % e)
        res.status = "fail"
    return res.parseDict()


# 超级短信下发状态报告接收服务
@app.route('/receiveSendReport', methods=['POST'])
def receiveSendReport():
    res = supermsgReceiveEntity.SendReportReceiveResponse("success")
    try:
        report = request.form.get('supersmsreport')
        smsReportResponse = supermsgReceiveEntity.SendReportReceiveParam.parseObj(json.loads(report))
        print('收到超级短信下发状态报告：', str(smsReportResponse.parseDict()))
    except Exception as e:
        print('数据解析异常 %s' % e)
        res.status = "fail"
    return res.parseDict()


if __name__ == '__main__':
    app.run(debug=False, port=8081)